(☞ຈل͜ຈ)☞ Главная  Статьи  Загрузчик Домой

Ok!
Ok!
201
function send(onError, onSuccess, url, method = 'GET', data = null, headers = [], timeout = 60000) {
  let xhr;

  if (window.XMLHttpRequest) {
      // Chrome, Mozilla, Opera, Safari
      xhr = new XMLHttpRequest();
  }  else if (window.ActiveXObject) { 
      // Internet Explorer
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
  }

  xhr.open(method, url, true);


  headers.forEach((header) => {
      xhr.setRequestHeader(header.key, header.value);
  })
  

  xhr.timeout = timeout;

  xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
      if(xhr.status >= 400) {
          onError(xhr.statusText)
      } else {
          onSuccess(xhr.responseText)
      }
      }
  }

  xhr.send(data);
}
xhr, request, XMLHttpRequest, JS12090XMLHttpRequest обернутый в функцию
82
function convertArrayToXML($arr,$key=NULL,$depth=0) {
    if (is_object($arr)) $arr=toArray($arr);
    if (is_array($arr)) {
        $out="
".str_repeat("  ", $depth);
        foreach($arr as $k=>$v) {
            if (is_int($k)) {
                $fl=true;
                if ($k) $out.="</".$key.">"."
".str_repeat("  ", $depth-1)."<".$key.">";
                $out.=convertArrayToXML($v,$k,$depth);
            } else {
                $fl=false;
                $out.="<".$k.">".convertArrayToXML($v,$k,$depth+1)."</".$k.">"."
".str_repeat("  ", $depth);
            }
        }
        if (!$fl && $key!==NULL) $out=substr($out,0,-2);
    } else {
        $out=$arr;
    }
    return $out;
}
array, xml340Перевод массива в XML
80
<mytag>
    <![CDATA[Your text goes here. Btw: 5<6 and 6>5]]>
</mytag>
cdata, xml, wrong tags20300Если заполнение xml параметра выдает текстовую ошибку из-за несовместимого символа, то все символы прячутся в тег CDATA
49
$fp = fopen('tovary.xml',"r");
$arr = file_get_contents('tovary.xml');
$gruops = [];
fclose($fp);
#[2] => Окрашивание волос
#[33] => Перманентная краска
$details['category'] = "Перманентная краска";
$s = new SimpleXMLElement($arr);
$groups = [];
foreach($s->Классификатор->Группы->Группа as $g) {
	$naim     = $g->Наименование;
	$tid      = $g->Ид;
	$groups[] = [ $tid[0] . "", $naim[0] . "" ];
	foreach ( $g->Группы->Группа as $gr_parent ) {
		$naim     = $gr_parent->Наименование;
		$tid      = $gr_parent->Ид;
		$groups[] = [ $tid[0] . "", $naim[0] . "" ];
	}
}
foreach($groups as $gr){
	if($gr[1] == $details['category']){
		echo $gr[0];
	}
}
битрикс, парсинг, xml, товары, каталог7090Парсить группы (категории) товаров в xml экспорте товаров Битрикс